package iterator;

import javax.lang.model.element.NestingKind;

public class TCLTelevision implements Television {
    private String[] obj = {"湖南卫视", "北京卫视", "上海卫视", "湖北卫视", "黑龙江卫视"};

    public TVIterator createIterator() {
        return new TCLIterator();
    }

    class TCLIterator implements TVIterator {
        private int currentIndex = 0;

        public void next() {

            currentIndex = (currentIndex + 1) % obj.length;  // 循环切换

        }

        public void previous() {
            currentIndex = (currentIndex - 1 + obj.length) % obj.length;  // 循环切换
        }

        public void setChannel(int i) {
            if (i >= 0 && i < obj.length) {
                currentIndex = i;
            }
        }


        public Object currentChannel() {
            return obj[currentIndex];
        }

        public boolean isLast() {
            return currentIndex == obj.length - 1;
        }

        public boolean isFirst() {
            return currentIndex == 0;
        }
    }
}